#define _CRT_SECURE_NO_WARNINGS 1

#include "game.h"

//初始化棋盘
void Initialize(char arr[ROWS][COLS], int rows, int cols, char c)
{
	int i = 0;
	for (i = 0; i < rows; i++)
	{
		int j = 0;
		for (j = 0; j < cols; j++)
		{
			arr[i][j] = c;
		}
	}
}

//打印棋盘
void Print(char arr[ROWS][COLS], int row, int col)
{
	int i = 0;
	//打印横坐标
	for (i = 0; i <= row; i++)
	{
		printf("%d ", i);
	}
	printf("\n");
	for (i = 1; i <= row; i++)
	{
		printf("%d ", i);//打印纵坐标
		int j = 0;
		for (j = 1; j <= col; j++)
		{
			printf("%c ", arr[i][j]);
		}
		printf("\n");
	}
}

//埋雷
void SetTNT(char mine[ROWS][COLS], int row, int col)
{
	int TNT = Easy_TNT;
	while (TNT)
	{
		int x = rand() % row + 1;
		int y = rand() % col + 1;
		if ('0' == mine[x][y])
		{
			mine[x][y] = '1';
			TNT--;
		}
	}
}

//统计被排查坐标四周有没有雷
int Sround(char mine [ROWS][COLS],int x, int y)
{
	int i = 0;
	int sum = 0;
	for (i = x - 1; i <= x + 1; i++)
	{
		int j = 0;
		for (j = y - 1; j <= y + 1; j++)
		{
			sum += (mine[i][j] - '0');
		}
	}
	return sum;
}

//排查雷
InvestigateTNT(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
{
	int x = 0;
	int y = 0;
	int count = 0;
	while (count < 71)
	{
		//打印棋盘
		Print(show, ROW, COL);
		printf("请输入要排查的坐标->:");
		scanf("%d%d", &x, &y);
		//判断坐标是否合法
		if ('*' == show[x][y])
		{
			if ('1' == mine[x][y])
			{
				printf("很遗憾，您被炸死了！！！\n");
				break;
			}
			else
			{
				int ret = Sround(mine, x, y) + '0';
				show[x][y] = ret;
				count++;
			}
		}
		else
		{
			printf("该坐标已经被排查，请重新输入要排查的坐标\n");
		}
	}
	if (71 == count)
	{
		printf("恭喜您，扫雷成功，您就是雷王！！！\n");
	}
}
